import appModuleHandler, tones, ui
from scriptHandler import script
from NVDAObjects import NVDAObjectTextInfo
from controlTypes.role import Role
from . import chat
# 应用模块
class AppModule(appModuleHandler.AppModule):
    def event_NVDAObject_init(self, obj):
        # 修正微信的控件浏览光标不能获取到信息
        if Role.EDITABLETEXT != obj.role:
            obj.displayText = obj.name
            obj.TextInfo = NVDAObjectTextInfo
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 初始化聊天助手
        chat.init()
    def terminate(self):
        super().terminate()
        # 释放资源
        chat.release ()
    def event_foreground(self, obj, nextHandler):
        # 如果窗口改变要清除消息列表的缓存
        chat.reset()
    def event_gainFocus(self, obj, nextHandler):
        # 网络错误提示
        if 'NetErrInfoTipsBarWnd' == obj.windowClassName:
            ui.message (obj.displayText)
            return
        nextHandler()
    @script(gesture="kb:f12")
    def script_switchAutoSpeakMsg (self, gesture):
        # 自动朗读消息开关
        chat.switchAutoSpeakMsg ()
    @script(gesture="kb:f11")
    def script_voiceChat(self, gesture):
        # 语音聊天
        chat.clickButton('语音聊天')
    @script(gesture="kb:f10")
    def script_videoChat(self, gesture):
        # 视频聊天
        chat.clickButton('视频聊天')
